package javaBean;

import java.lang.reflect.Method;

public class AccessPersonMethods {
    public static void main(String[] args) {
        try {
            Class clz = Class.forName("javaBean.Person");
            Method getAge = clz.getDeclaredMethod("getAge",null);
            getAge.setAccessible(true);
            Object o = getAge.invoke(null,null);
            System.out.println("年龄是："+o);
            Object person = clz.newInstance();
            Method silent = clz.getDeclaredMethod("silentMethod",null);
            silent.setAccessible(true);
            silent.invoke(person,null);
            Method setName = clz.getDeclaredMethod("setName",String.class);
            setName.invoke(person,"New Person");
            Object name = clz.getDeclaredMethod("getName").invoke(person);
            System.out.println("刚才设定的name是："+name);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
